using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace ECommerce.Library.Web
{
    public class CookieManager
    {
        //constructor
        public CookieManager() { }

        public static bool SetCookieValue(string key, string value, DateTime expires)
        {
            if (IsCookieExists(key))
            {
                HttpCookie oldCookie = HttpContext.Current.Request.Cookies[key];
                oldCookie.Expires = DateTime.Now.AddDays(-1); ;
                System.Web.HttpContext.Current.Response.Cookies.Add(oldCookie);
            }
            HttpCookie cookie = new HttpCookie(key, value);
            cookie.Expires = expires;
            HttpContext.Current.Response.Cookies.Add(cookie);
            if (IsCookieExists(key))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static string GetCookieValue(string key)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[key];
            return cookie.Value;
        }

        public static bool RemoveCookie(string key)
        {
            if (IsCookieExists(key))
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies[key];
                cookie.Expires = DateTime.Now.AddDays(-1); ;
                HttpContext.Current.Response.Cookies.Add(cookie);
                return true;
            }
            return false;
        }

        public static bool IsCookieExists(string key)
        {
            if (HttpContext.Current.Request.Cookies[key] != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public const string USER_NAME = "AutoGearUserName";
        public const string PASSWORD = "AutoGearPassword";

    }
}
